# coding=utf-8
# from sqlalchemy import Column, String, create_engine
# from sqlalchemy.orm import sessionmaker
# from sqlalchemy.ext.declarative import declarative_base


import tushare as ts
import json

# import pymysql
# pymysql.install_as_MySQLdb()

# df = ts.get_realtime_quotes('000581') 
df = ts.get_index()
# print(df)
print df.head(3).to_json(orient='records')

# 新闻
# df = ts.get_latest_news(top=1,show_content=True)
# print(df)
# print(json.loads(df.head(1).to_json(orient='records'), encoding="utf-8"))

# df = ts.get_realtime_quotes('000581')
# print(df)

# 创建对象的基类
# Base = declarative_base()

# class User(Base):

#     __tablename__ = 'users'

#     id = Column(Integer, primary_key=True)
#     username = Column(String(64), nullable=False, index=True)
#     password = Column(String(64), nullable=False)
#     email = Column(String(64), nullable=False, index=True

# engine = create_engine("mysql://root:GZcEaP3Z@121.41.55.136/share?charset=utf8")
# 创建数据表，如果数据表存在，则忽视
# Base.metadata.create_all(engine)

# engine = create_engine("mysql://root:GZcEaP3Z@121.41.55.136/share?charset=utf8")

# # 存入数据库
# df.to_sql('new_demo',engine)

